//
//  KeyFrameViewController.swift
//  swiftAnimation
//
//  Created by zhouLiHuan on 2017/2/16.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

import UIKit

class KeyFrameViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.white;
        
        //方块旋转
        let tempView = UIView(frame:CGRect(x:50,y:100,width:250,height:500))
        let bezierPath = UIBezierPath(ovalIn:tempView.frame);
     
        let animView = UIView(frame:CGRect(x:50,y:100,width:70,height:80));
        animView.backgroundColor = UIColor.red;
        view.addSubview(animView);
        
        let orbitAnim = CAKeyframeAnimation(keyPath:"position");
        orbitAnim.duration = 05;
        orbitAnim.path = bezierPath.cgPath;
        orbitAnim.calculationMode = kCAAnimationPaced;
        orbitAnim.fillMode = kCAFillModeForwards;
        orbitAnim.repeatCount = Float.infinity;
        orbitAnim.rotationMode = kCAAnimationRotateAutoReverse;
        animView.layer.add(orbitAnim, forKey: "orbitAnim");
        
        //椭圆的线
        let shapeLayer = CAShapeLayer()
        shapeLayer.strokeColor = UIColor.purple.cgColor;
        shapeLayer.fillColor = UIColor.clear.cgColor;
        shapeLayer.lineWidth = 0.5;
        shapeLayer.lineJoin = kCALineJoinRound;
        shapeLayer.lineCap = kCALineCapRound;
        shapeLayer.path = bezierPath.cgPath;
        view.layer.addSublayer(shapeLayer);
  
        
    }

}
